<template>
  <div>
    <el-table v-loading="loading" :data="data" size="mini" border style="width: 100%;" stripe highlight-current-row>
      <el-table-column type="index" label="序号" header-align="center" align="center" />
      <el-table-column show-overflow-tooltip prop="opc.id" label="opc点位名称" />
      <el-table-column show-overflow-tooltip prop="station.name" label="工厂">
        {{ "csot-t4" }}
      </el-table-column>
      <el-table-column show-overflow-tooltip prop="building.name" label="建筑" />
      <el-table-column show-overflow-tooltip prop="point.name" label="point" />

      <el-table-column show-overflow-tooltip prop="machine.name" label="设备" />
      <el-table-column show-overflow-tooltip prop="tag.name" label="参数" />
      <el-table-column label="操作" width="150px" align="center">
        <template slot-scope="scope">
          <!-- <el-button
            type="success"
            size="mini"
            class="el-btn"
            @click="$parent.operate(scope)"
          >编辑</el-button> -->
          <el-popover
            :ref="scope.row.opc.uid"
            placement="top"
            width="180"
          >
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.opc.uid].doClose()">取消</el-button>
              <el-button :loading="loading" type="primary" size="mini" @click="subDelete(scope.row)">确定</el-button>
            </div>
            <el-button slot="reference" type="danger" size="mini">删除</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="total"
      :current-page="currentPage"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"
    />
  </div>
</template>
<script>
export default {
  props: {
    data: { // tree list data set
      type: Array,
      required: true,
      default: () => []
    }
  },
  data() {
    return {
      loading: false, page: 0, size: 10, total: 0, url: '', params: {}, time: 170, currentPage: 1
    }
  },
  methods: {
    pageChange(e) {
      this.page = e - 1
      this.currentPage = e
      this.init()
    },
    sizeChange(e) {
      this.currentPage = 1
      this.page = 0
      this.size = e
      this.init()
    },
    subDelete(row) {
      const res = this.$parent.service.deleteOpcRelation(row)
      // console.log(row)
      this.loading = false
      if (res.flag) {
        // this.resetForm()
        this.loading = false
        this.$refs[row.opc.uid].doClose()
        // this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
        this.dialog = false
      } else {
        this.$refs[row.opc.uid].doClose()
        this.$notify({
          title: '删除失败',
          type: 'error',
          duration: 2500
        })
      }
    }
  }
}
</script>
